<template>
  <div class="sourceManage">
    <el-card class="box-card">
      <el-scrollbar wrapClass="scrollbar-wrapper">
        <el-form
          :inline="true"
          class="demo-form-inline"
          size="mini"
          v-model="queryForm"
        >
          <el-row>
            <el-form-item>
              <el-button
                size="small"
                type="primary"
                icon="el-icon-plus"
                @click="showFormEvent()"
                >新增数据表</el-button
              >
              <!-- <el-button size="small" type="primary"  @click="showFormEvent()">刷新</el-button> -->
              <!-- <el-button size="small" type="warning"  @click="showFormEvent()">删除</el-button> -->
            </el-form-item>
          </el-row>
          <el-form-item label="创建时间">
            <el-date-picker
              value-format="yyyy-MM-dd"
              v-model="queryForm.createDate"
              type="date"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="表单日期">
            <el-date-picker
              value-format="yyyy-MM-dd"
              v-model="queryForm.formDate"
              type="date"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="行政区划">
            <el-input
              v-model="queryForm.regionName"
              placeholder="输入地址"
            ></el-input>
            <!-- <el-date-picker
              value-format="yyyy-MM-dd"
              v-model="queryForm.regionName"
              type="date"
              placeholder="选择日期"
            ></el-date-picker> -->
          </el-form-item>
          <el-form-item>
            <el-button
              size="small"
              type="primary"
              icon="el-icon-search"
              @click="searchEvent"
              >搜索</el-button
            >
          </el-form-item>
        </el-form>
        <znxd-list
          :column="column"
          :page="page"
          :tableData="tableData"
          @handlePageChange="handlePageChange(page)"
          :pagination="true"
        ></znxd-list>
      </el-scrollbar>
    </el-card>
    <!-- 表单弹出框 -->
    <!-- <fileServerDIalog
      :databaseFormVisible="databaseFormVisible"
      :initData="formData"
      @close="fromClose"
    ></fileServerDIalog> -->
    <!-- 表单弹出框 -->
  </div>
</template>

<script >
import { list, del } from "@/api/task/fileserver.js"
import { manualEntryList, deleteManualEntry } from "@/api/manualEntry/manualEntry.js"
import { getDiction, formatTime } from "@/utils/config.js"
// import fileServerDIalog from "./fileServerDIalog"

export default {
  components: {
    // fileServerDIalog
  },
  data () {
    return {
      // 是否配置
      isConfigOptions: [
        {
          label: "未配置",
          value: "0"
        },
        {
          label: "已配置",
          value: "1"
        }
      ],
      page: {
        pageNo: 1, // 当前位于哪页
        pageSize: 10, // 1页显示多少条
        total: 0
      },
      // 搜索条件
      queryForm: {},
      tableData: [],
      // 列表配置
      column: [
        {
          align: "center",
          name: "tableName",
          label: "数据表名称",
          showOverflowTooltip: true
        },
        {
          align: "center",
          name: "isConfig",
          label: "是否配置",
          showOverflowTooltip: true,
          handleGetName: (code) => {
            return getDiction(this.isConfigOptions, code)
          }
        },
        {
          align: "center",
          name: "createDate",
          label: "创建时间"
        },
        {
          align: "center",
          label: "操作",
          width: 300,
          buttons: [
            {
              label: "编辑",
              type: "primary",
              plain: false,
              size: "mini",
              handelClick: row => {
                this.showFormEvent(row)
              }
            },
            {
              label: "删除",
              type: "warning",
              plain: false,
              size: "mini",
              handelClick: row => {
                this.deleteEvent(row)
              }
            },
            {
              label: "配置",
              type: "danger",
              plain: true,
              size: "mini",
              handelClick: row => {
                this.setConfig(row)
              }
            }
          ]
        }
      ],
      // 表单管理
      databaseFormVisible: false,
      formData: {}
    }
  },
  methods: {
    // 列表操作
    searchEvent () {
      this.page.pageNo = 1
      this.getSourceData()
    },
    getSourceData () {
      let obj = {
        ...this.page,
        ...this.queryForm
      }
      delete obj.total
      if (obj.createDate) {
        obj.createDate = formatTime("yyyy-MM-dd", obj.createDate)
      }
      manualEntryList(obj).then(res => {
        console.log(res, 333)
        if (res.data.code === "200") {
          this.tableData = res.data.data.list
          this.page.total = res.data.data.total
        } else {
          this.$message({
            message: res.data.msg,
            type: "error"
          })
        }
      })
    },
    handlePageChange (page) {
      this.page = page
      this.getSourceData()
    },
    // form表单弹框操作
    // fromClose () {
    //   this.databaseFormVisible = false
    //   this.getSourceData()
    // },
    showFormEvent (row = {}) {
      this.$router.push({ path: "addDataList", query: { id: row.id } })
    },
    // 二级操作
    deleteEvent (row) {
      if (row.jobState === 1) {
        this.$message({
          type: "info",
          message: "任务启用，不能删除"
        })
        return
      }

      this.$confirm("确认删除吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let obj = {
            id: row.id
          }
          deleteManualEntry(obj)
            .then(res => {
              console.log(res)
              if (res.data.code === "200") {
                this.$message({
                  type: "success",
                  message: res.data.msg || "操作成功"
                })
                this.getSourceData()
              } else {
                this.$message({
                  type: "error",
                  message: res.data.msg
                })
              }
            })
            .catch(() => {
              this.$message({
                type: "error",
                message: "操作失败"
              })
            })
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          })
        })
    },
    setConfig (row) {
      this.$router.push({ path: "settingDataList", query: { id: row.id } })
    }
  },
  mounted () {
    this.getSourceData()
  }
};
</script>
<style lang="scss" scoped>
@import "../../assets/style/style.scss";
@import "../../assets/style/variable.scss";
</style>
